/****************************************************************************************
 Copyright © 2003-2012 ZTEsoft Corporation. All rights reserved. Reproduction or       <br>
 transmission in whole or in part, in any form or by any means, electronic, mechanical <br>
 or otherwise, is prohibited without the prior written consent of the copyright owner. <br>
 ****************************************************************************************/
package com.iwhalecloud.bss.kite.cucc.service.cust;

import com.iwhalecloud.bss.kite.client.api.cust.query.IQueryLocalCustService;
import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.client.dto.cust.CustDTO;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.reception.ICustReceptionService;
import com.iwhalecloud.bss.kite.cucc.client.dto.scene.CuccCustInfoDetailDTO;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.dataservice.cache.DcSystemParamCache;
import com.ztesoft.common.logger.api.ZLogger;
import com.ztesoft.common.logger.factory.ZLoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <Description> <br>
 *
 * @author lifl<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2019年5月11日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.service.cust <br>
 */
@Service("cucc.queryCustService")
public class QueryCustService implements IQueryLocalCustService {

    private static final ZLogger LOGGER = ZLoggerFactory.getLogger(QueryCustService.class, KeyConsts.LOG_MODULE);
    @Autowired
    private ICustReceptionService custReceptionService;

    @Override
    public DataResult<CustDTO> getCustInfo(String custId, List<Object> scopeList) {
        //收入归集集团临时客户信息-只用于场景初始化-批量导入时没有选择客户
        if (KiteStringUtils.equals(custId,DcSystemParamCache.getDcParamVal(LocalKeyConsts.COLLECTION_GROUP_CUST_ID))){
            CustDTO dto =new CustDTO();
            dto.setCustId(custId);
            dto.setCustName("收入归集集团临时客户");
            return ErrorConsts.SUCCESS.getResult(dto);
        }

        CustDTO dto = new CustDTO();
        CuccCustInfoDetailDTO cuccCustInfoDTO = custReceptionService.getCustomerInfoNew(custId);
        if (Objects.nonNull(cuccCustInfoDTO)) {
            KiteBeanUtils.copyProperties(cuccCustInfoDTO, dto);

            //dto.setProvinceCode(cuccCustInfoDTO.getProvinceCode());
            dto.setLanId(cuccCustInfoDTO.getCityCode());
            dto.setRegionId(cuccCustInfoDTO.getBcityCode());
            dto.setCustType(cuccCustInfoDTO.getCustClassType());
            dto.setCertiType(cuccCustInfoDTO.getCertiTypeCode());
            dto.setCertiNumber(cuccCustInfoDTO.getCertiCode());
            //dto.setBbssCustId(cuccCustInfoDTO.getBbssCustId());
            //dto.setCbssId(cuccCustInfoDTO.getCustId());
        }
    	return ErrorConsts.SUCCESS.getResult(dto);
    }

}
